package com.qing.servicebase.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName: CheckTool
 * @Author:
 * @Version: 1.0
 * @description: 校验工具类
 *               校验手机号
 *               校验邮箱号
 **/
public class CheckTool {
    /**
     * 邮箱正则表达式
     */
    private static final String CHECK_EMAIL =
            "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    /**
     * 手机号正则表达式
     */
    private static final String CHECK_PHONE =
            "^(13[4,5,6,7,8,9]|15[0,8,9,1,7]|188|187)\\d{8}$";

    /**
     * 判断是否为邮箱  是返回true，不是返回false
     * @param email 需要校验的邮箱号
     * @return boolean
     */
    public static boolean isEmail(String email) {
        if (null == email || "".equals(email)) {
            return false;
        }
        Pattern regex = Pattern.compile(CHECK_EMAIL);
        Matcher matcher = regex.matcher(email);
        return matcher.matches();
    }

    /**
     * 判断是否为手机号 是返回true，不是返回false
     * @param phone 需要校验的手机号
     * @return boolean
     */
    public static boolean isPhone(String phone) {
        if (null == phone || "".equals(phone)) {
            return false;
        }
        Pattern regex = Pattern.compile(CHECK_PHONE);
        Matcher matcher = regex.matcher(phone);
        return matcher.matches();
    }

}
